package operations;

import book.Book;
import book.BookList;

import java.util.Scanner;

public class AddOperation implements IOperation{
    //为了方便，只用了尾插
    public void work(BookList bookList) {
        System.out.println("新增图书！");

        Scanner scanner = new Scanner(System.in);
        System.out.println("请输入图书的名字:>");
        String addName = scanner.nextLine();
        System.out.println("请输入图书的作者:>");
        String addAuthor = scanner.nextLine();
        System.out.println("请输入图书的价格:>");
        int addPrice = scanner.nextInt();
        scanner.nextLine();//处理int后的回车键
        System.out.println("请输入图书的类型:>");
        String addType = scanner.nextLine();

        //新建的addBook书
        Book addBook = new Book(addName,addAuthor,addPrice,addType);
        int currentUserSize = bookList.getUsedSize();//获取放入位置下表
        //把书放入书架
        bookList.setBooks(addBook, currentUserSize);
        //UserSize++的方式
        //1、在setBook方法中: this.UserSize++;
        //2、在bookList中创建setUserSize方法，就是下面这种
        bookList.setUsedSize(currentUserSize+1);

        System.out.println("新增图书完成！");

    }
}
